
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class EditUserPanel : BasePanel
    {
        public Button btnOK;
        public Button btnCancel;
        public TMP_InputField input;
        public string curUserName;
        public string CurName
        {
            get { return curUserName; }
            set
            {
                curUserName = value;
                input.text = curUserName;
            }
        }

        private void Awake()
        {
            btnOK.onClick.AddListener(OnBtnOK);
            btnCancel.onClick.AddListener(OnBtnCancel);
        }

        public void OnBtnOK()
        {
            UserData userData = DataManager.LoadUserData(curUserName);
            DataManager.ClearUserData(curUserName);
            DataManager.SaveUserData(new UserData(input.text, userData.level));
            DataManager.SaveClientData(new ClientData(input.text));
            UserEvents.UserList();
            ClosePanel();
            UIManager.Instance.ClosePanel(UIConst.UserListPanel);
        }

        public void OnBtnCancel()
        {
            ClosePanel();
        }
    }
}
